﻿using Microsoft.Office.Interop.Excel;
using System.Linq;

namespace Citi.SecurityHelper
{
    public class SecureExcel
    {
        public static Workbook GetSecureWorkbook(string xlsFile, string pwdFile, Application application)
        {
            return GetOpenedWorkbook(xlsFile, pwdFile, application);
        }

        static public  Workbook GetOpenedWorkbook(string xlsFile, string pwdFile, Application application)
        {
            object nullValue = System.Reflection.Missing.Value;
            var password = CitiPasswordFile.GetDecryptedText(pwdFile, SecurityConfigurations.RobotUserName, SecurityConfigurations.RobotPassword).FirstOrDefault(); 

           return application.Workbooks.Open(
                xlsFile, nullValue, false, nullValue, password ?? nullValue,
                password ?? nullValue, true, nullValue, nullValue, true,
                false, nullValue, nullValue, nullValue, nullValue);
        }
    }
}
